package com.example.ordersystem.service;

import com.example.ordersystem.entity.Comment;
import com.example.ordersystem.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CommentService {
    @Autowired
    private CommentRepository commentRepository;

    public Comment addComment(Comment comment) {
        comment.setCommentTime(LocalDateTime.now());
        return commentRepository.save(comment);
    }

    public List<Comment> getCommentsByOrderId(Long orderId) {
        return commentRepository.findByOrderId(orderId);
    }

    public List<Comment> getAllComments() {
        return commentRepository.findAll();
    }

    public Comment replyToComment(Long commentId, String reply) {
        Comment comment = commentRepository.findById(commentId).orElse(null);
        if (comment != null) {
            comment.setReply(reply);
            comment.setReplyTime(LocalDateTime.now());
            return commentRepository.save(comment);
        }
        return null;
    }
} 